package com.tbq.tbqj_ggl.windows

import android.app.Activity
import android.content.Intent
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.tbq.sdk.TBQ

import com.tbq.tbqj_ggl.activity.ScratchFKLCGameActivity
import com.tbq.tbqj_ggl.activity.ScratchHorseRacingGameActivity
import com.tbq.tbqj_ggl.activity.ScratchPrizesGameActivity
import com.tbq.tbqj_ggl.activity.ScratchYGQJGameActivity

import com.tbq.tbqj_ggl.R
import com.tbq.tbqj_ggl.app.AppBasePopupWindow
import com.tbq.tbqj_ggl.app.V

/**
 * 后台管理界面
 * Created by hais1992 on 15-5-28.
 */
class ScratchPrizeTypeWindow(activity: Activity, private val listener: Listener) : AppBasePopupWindow(activity,
        if(TBQ.get("KEY_IS_MOBILE") == "1") R.layout.mobile_windows_scratch_prizes_type else  R.layout.windows_scratch_prizes_type), View.OnClickListener {
    private var mIamge: ImageView? = null
    private var btqueidng: Button? = null
    private var mtext: TextView? = null
    private var type: Int = 0

    override fun drawEnd(view: View) {
        mIamge = view.findViewById(R.id.windows_scrach_type_image) as ImageView
        mIamge!!.setOnClickListener(this)
        btqueidng = view.findViewById(R.id.id_scratch_type_bt_queding) as Button
        btqueidng!!.setOnClickListener(this)
        mtext = view.findViewById(R.id.id_windows_scratch_type_text) as TextView
        initDates()
    }

    private fun initDates() {
        mtext!!.text = "1.刮奖可以选择多种面额,面额越大奖品越丰富。\n" +
                "2.刮开覆盖层，如果刮奖区任意一个\"奖品\"与开奖区相同，即可获得开奖区奖品。\n" +
                "刮奖区其他的\"奖品\"与开奖区不同的\"奖品\"无效。\n" +
                "3.中奖后选择领取奖品方式。\n" +
                "4.\"再来一次\"即放弃本局刮奖,并消耗相应面额金币进行下一轮刮奖。"
    }


    fun showCenter(i: Int) {
        showCenter()
        this.type = i
        btqueidng!!.performClick()
    }

    interface Listener {
        fun clickListener(number: Int)
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.id_scratch_type_bt_queding -> {
                startupWindows(type)
                dismiss()
            }
            R.id.windows_scrach_type_image -> dismiss()
        }

    }

    fun startupWindows(i: Int) {
        val intent = Intent()
        when (i) {
            1 -> intent.setClass(activity, ScratchPrizesGameActivity::class.java)
            2 -> {
            }
            3 -> intent.setClass(activity, ScratchHorseRacingGameActivity::class.java)
            4 -> intent.setClass(activity, ScratchYGQJGameActivity::class.java)
            5 -> intent.setClass(activity, ScratchFKLCGameActivity::class.java)
        }//  intent.setClass(activity, ScratchTextGameActivity.class);
        V.GAME_TYPE = i
        activity.startActivity(intent)
        dismiss()
        activity.finish()
    }


}
